<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_interpolationAnalystByDen"></title>
    <script type="text/javascript" src="../js/include-web.js"></script>
    <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
<div id="map" style="width: 100%;height:100%"></div>
<script type="text/javascript">
    var map, options, interpolationAnalystResult,
        baseUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/map-temperature/rest/maps/全国温度变化图",
        serviceUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst";
    var extent = [-2640403.63, 1873792.1, 3247669.39, 5921501.4];
    var projection = new ol.proj.Projection({
        code:'',
        extent: extent,
        units: 'm'
    });
    new ol.supermap.MapService(baseUrl).getMapInfo().then(function (serviceResult) {
        var mapJSONObj = serviceResult.result;
        map = new ol.Map({
            target: 'map',
            // ol v7版本用法为ol.control.defaults.defaults； v6版本以下用法为ol.control.defaults
            controls: ol.control.defaults.defaults({attributionOptions: {collapsed: false}})
                .extend([new ol.supermap.control.Logo({ link: "https://iclient.supermap.io" })]),
            view: new ol.View({
                center: [531762, 3580330],
                zoom: 1,
                projection: projection,
                multiWorld: true
            })
        });
        options = ol.source.TileSuperMapRest.optionsFromMapJSON(baseUrl, mapJSONObj);
        options.layersID = "[0,1,2]";
        var layer = new ol.layer.Tile({
            source: new ol.source.TileSuperMapRest(options)
        });
        map.addLayer(layer);
        interpolationAnalystProcess();
    });

    function interpolationAnalystProcess() {
        //创建点密度插值分析参数实例
        var interpolationAnalystParameters = new ol.supermap.InterpolationDensityAnalystParameters({
            //用于做插值分析的数据源中数据集的名称
            dataset: "SamplesP@Interpolation",
            //插值分析结果数据集的名称
            outputDatasetName: "Density_Result",
            //插值分析结果数据源的名称
            outputDatasourceName: "Interpolation",
            //结果栅格数据集存储的像素格式
            pixelFormat: ol.supermap.PixelFormat.DOUBLE,
            //插值结果栅格数据集的分辨率
            resolution: 9000,
            // 存储用于进行插值分析的字段名称
            zValueFieldName: "AVG_TMP",
            //结果栅格数据集的范围（生效）
            bounds: [-2640403.63, 1873792.1, 3247669.39, 5921501.4]
        });
        new ol.supermap.SpatialAnalystService(serviceUrl).interpolationAnalysis(interpolationAnalystParameters, function (serviceResult) {
            interpolationAnalystResult = serviceResult.result;
            //用栅格专题图展示分析结果
            showAnalysisResult_ThemeGridRange();
        });

        //构造栅格专题图
        function showAnalysisResult_ThemeGridRange() {
            var color1 = new ol.supermap.ServerColor(170, 240, 233),
                color2 = new ol.supermap.ServerColor(176, 244, 188),
                color3 = new ol.supermap.ServerColor(218, 251, 178),
                color4 = new ol.supermap.ServerColor(220, 236, 145),
                color5 = new ol.supermap.ServerColor(96, 198, 66),
                color6 = new ol.supermap.ServerColor(20, 142, 53),
                color7 = new ol.supermap.ServerColor(85, 144, 55),
                color8 = new ol.supermap.ServerColor(171, 168, 38),
                color9 = new ol.supermap.ServerColor(235, 165, 9),
                color10 = new ol.supermap.ServerColor(203, 89, 2),
                color11 = new ol.supermap.ServerColor(157, 25, 1),
                color12 = new ol.supermap.ServerColor(118, 15, 3),
                color13 = new ol.supermap.ServerColor(112, 32, 7),
                color14 = new ol.supermap.ServerColor(106, 45, 12),
                color15 = new ol.supermap.ServerColor(129, 80, 50),
                color16 = new ol.supermap.ServerColor(160, 154, 146),
                color17 = new ol.supermap.ServerColor(107, 47, 14),
                color18 = new ol.supermap.ServerColor(125, 75, 44),
                color19 = new ol.supermap.ServerColor(146, 110, 88),
                color20 = new ol.supermap.ServerColor(166, 153, 146);

            var themeGridRangeItem1 = new ol.supermap.ThemeGridRangeItem({
                    start: -5,
                    end: -3.4,
                    color: color1
                }),
                themeGridRangeItem2 = new ol.supermap.ThemeGridRangeItem({
                    start: -3.4,
                    end: -1.8,
                    color: color2
                }),
                themeGridRangeItem3 = new ol.supermap.ThemeGridRangeItem({
                    start: -1.8,
                    end: -0.2,
                    color: color3
                }),
                themeGridRangeItem4 = new ol.supermap.ThemeGridRangeItem({
                    start: -0.2,
                    end: 1.4,
                    color: color4
                }),
                themeGridRangeItem5 = new ol.supermap.ThemeGridRangeItem({
                    start: 1.4,
                    end: 3,
                    color: color5
                }),
                themeGridRangeItem6 = new ol.supermap.ThemeGridRangeItem({
                    start: 3,
                    end: 4.6,
                    color: color6
                }),
                themeGridRangeItem7 = new ol.supermap.ThemeGridRangeItem({
                    start: 4.6,
                    end: 6.2,
                    color: color7
                }),
                themeGridRangeItem8 = new ol.supermap.ThemeGridRangeItem({
                    start: 6.2,
                    end: 7.8,
                    color: color8
                }),
                themeGridRangeItem9 = new ol.supermap.ThemeGridRangeItem({
                    start: 7.8,
                    end: 9.4,
                    color: color9
                }),
                themeGridRangeItem10 = new ol.supermap.ThemeGridRangeItem({
                    start: 9.4,
                    end: 11,
                    color: color10
                }),
                themeGridRangeItem11 = new ol.supermap.ThemeGridRangeItem({
                    start: 11,
                    end: 12.6,
                    color: color11
                }),
                themeGridRangeItem12 = new ol.supermap.ThemeGridRangeItem({
                    start: 12.6,
                    end: 14.2,
                    color: color12
                }),
                themeGridRangeItem13 = new ol.supermap.ThemeGridRangeItem({
                    start: 14.2,
                    end: 35.8,
                    color: color13
                }),
                themeGridRangeItem14 = new ol.supermap.ThemeGridRangeItem({
                    start: 35.8,
                    end: 57.4,
                    color: color14
                }),
                themeGridRangeItem15 = new ol.supermap.ThemeGridRangeItem({
                    start: 57.4,
                    end: 79,
                    color: color15
                }),
                themeGridRangeItem16 = new ol.supermap.ThemeGridRangeItem({
                    start: 79,
                    end: 90.6,
                    color: color16
                }),
                themeGridRangeItem17 = new ol.supermap.ThemeGridRangeItem({
                    start: 90.6,
                    end: 112.2,
                    color: color17
                }),
                themeGridRangeItem18 = new ol.supermap.ThemeGridRangeItem({
                    start: 112.2,
                    end: 123.8,
                    color: color18
                }),
                themeGridRangeItem19 = new ol.supermap.ThemeGridRangeItem({
                    start: 123.8,
                    end: 125.4,
                    color: color19
                }),
                themeGridRangeItem20 = new ol.supermap.ThemeGridRangeItem({
                    start: 125.4,
                    end: 135,
                    color: color20
                });

            var themeGridRange = new ol.supermap.ThemeGridRange({
                reverseColor: false,
                rangeMode: ol.supermap.RangeMode.EQUALINTERVAL,
                //栅格分段专题图子项数组
                items: [themeGridRangeItem1, themeGridRangeItem2,
                    themeGridRangeItem3, themeGridRangeItem4,
                    themeGridRangeItem5, themeGridRangeItem6,
                    themeGridRangeItem7, themeGridRangeItem8,
                    themeGridRangeItem9, themeGridRangeItem10,
                    themeGridRangeItem11, themeGridRangeItem12,
                    themeGridRangeItem13, themeGridRangeItem14,
                    themeGridRangeItem15, themeGridRangeItem16,
                    themeGridRangeItem17, themeGridRangeItem18,
                    themeGridRangeItem19, themeGridRangeItem20
                ]
            });

            var themeParameters = new ol.supermap.ThemeParameters({
                //制作专题图的数据集
                datasetNames: [interpolationAnalystResult.dataset.split('@')[0]],
                dataSourceNames: ["Interpolation"],
                joinItems: null,
                themes: [themeGridRange]
            });

            new ol.supermap.ThemeService(baseUrl).getThemeInfo(themeParameters).then(function (serviceResult) {
                var result = serviceResult.result;
                if (result && result.newResourceID) {
                    var themeLayer = new ol.layer.Tile({
                        source: new ol.source.TileSuperMapRest({
                            url: baseUrl,
                            noWrap: true,
                            cacheEnabled: false,
                            layersID: result.newResourceID,
                            tileGrid: new ol.tilegrid.TileGrid({
                                extent: extent,
                                resolutions: options.tileGrid.getResolutions()
                            }),
                            transparent: true
                        })
                    });
                    map.addLayer(themeLayer);
                }
            });
        }
    }
</script>
</body>
</html>